/**
 * Created by hzq16239 on 2016/1/20.
 */
'use strict';

var util = require('util');
var offlineConfig = require('../offlineConfig.js');
var defaultConf = offlineConfig;

module.exports.defaultConf = defaultConf;

var mongoose = require('mongoose');
var mongodbCon = offlineConfig.mongodb;
//可能还存在使用 用户名和账号的情况。
var mongodbString =  util.format('mongodb://%s:%s/%s',mongodbCon.server,mongodbCon.port,mongodbCon.db);
//console.log(mongodbString);
//console.log(mongodbServer);
var mongooseConnection = mongoose.createConnection(mongodbString);

//add event handler
mongooseConnection.on('error',function(){
    console.error("mongo connect occured some error");
});

mongooseConnection.once('open',function(){
    console.log("mongo connected");
});

module.exports.mongooseCollection = mongooseConnection;